package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;

public class FormOwiAHT extends Form implements FormOwi{

  OWIAgent owiAgent = null;
  ChoiceGroup location = new ChoiceGroup("Location", ChoiceGroup.EXCLUSIVE);
  TextField height = new TextField("Height (m)", "", 50, TextField.DECIMAL);
  ChoiceGroup type = new ChoiceGroup("Type", ChoiceGroup.EXCLUSIVE);

  public FormOwiAHT(OWIAgent o){
    super("Antenna Height");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(location);
    location.append("Attached", null);
    location.append("Remote", null);
    location.setSelectedIndex(0, true);
    append(height);
    append(type);
    type.append("Vertical", null);
    type.append("Slope", null);

  }

  public void update(){
    owiAgent.query(OWI.qsAHT(OWI.location));

    location.setSelectedIndex(OWI.location, true);
    height.setString(OWI.height);
    type.setSelectedIndex(OWI.type, true);
  }

  public void save() {

    String msgId = "AHT";

    // Setup SET parameters
    String[] outputs = {msgId,
                       "" + location.getSelectedIndex(),
                       height.getString(),
                       "" + type.getSelectedIndex()
    };

    //Send message and update form if successful
    int ackCode = (owiAgent.set(msgId, OWI.setMessage(outputs)));
    Controller.showACKAlert(this,this,ackCode);
  }
}
